<template>
    <div>
        <h1>当前求和为：{{sum}}</h1>
        <!-- <select v-model="num">
            <option :value="1">1</option>
            <option :value="2">2</option>
            <option :value="3">3</option>
        </select> -->
         <select v-model.number="num">
            <option :value="1">1</option>
            <option :value="2">2</option>
            <option :value="3">3</option>
        </select>
        <button @click="add">+</button>
        <button @click="dec">-</button>
        <button @click="addOdd">当前求和为奇数再加</button>
        <button @click="addWait">等一等再加</button>
    </div>
</template>

<script>
     export default {
        name:'count',
        data() {
            return {
                num:1,
                sum:0,//当前的和
            }
        },
        methods: {
            add(){
                this.sum+=this.num
            },
            dec(){
                this.sum-=this.num
            },
            addOdd(){
                if(this.num%2){
                    this.sum+=this.num
                }
            },
            addWait(){
                setTimeout(() => {
                    this.sum+=this.num
                }, 500);
            },
        },

     }
</script>

<style scoped>
    button {
        margin-left: 10px;
    }
</style>